package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.UserLike;
import com.itheima.service.mongo.UserLikeService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class UserLikeServiceImpl implements UserLikeService {

    @Autowired
    private MongoTemplate mongoTemplate;

    // 是否喜欢
    @Override
    public Boolean findByUserIdAndLikeUserId(Long userId, Long likeUserId) {
        // 1.构造条件
        Query query = new Query(
                Criteria.where("userId").is(userId)
                        .and("likeUserId").is(likeUserId)
        );
        // 2.查询
        return mongoTemplate.exists(query, UserLike.class);
    }

    // 探花-喜欢
    @Override
    public void saveUserLike(UserLike userLike) {
        // 保存
        mongoTemplate.save(userLike);
    }
}
